package com.matt.repository.nursery;

import com.matt.domain.nursery.NurseryScheduleRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * *******************************
 * Created by lch.
 * form com.matt
 * on 2018/11/26
 * *******************************
 */

public interface NurseryScheduleRecordRepository  extends JpaRepository<NurseryScheduleRecord, String>, JpaSpecificationExecutor<NurseryScheduleRecord> {

    List<NurseryScheduleRecord> findByNurseryScheduleId(String nurseryScheduleId);

    Page<NurseryScheduleRecord> findByNurseryScheduleId(String nurseryScheduleId, Pageable pageable);

    Page<NurseryScheduleRecord> findByNurseryScheduleIdAndCategory(String nurseryScheduleId, Integer category,Pageable pageable);

    List<NurseryScheduleRecord> findByNurseryScheduleIdOrderByBeginDateAsc(String nurseryScheduleId);

    @Transactional
    @Modifying
    @Query(value = "delete from nursery_schedule_record where nurseryScheduleId=:nurseryScheduleId",nativeQuery = true)
    int deleteByNurseryScheduleId(@Param("nurseryScheduleId") String nurseryScheduleId);

    @Transactional
    @Modifying
    @Query(value = "delete from nursery_schedule_record where nurseryScheduleId=:nurseryScheduleId and category=:category",nativeQuery = true)
    int deleteByNurseryScheduleIdAndCategory(@Param("nurseryScheduleId") String nurseryScheduleId,@Param("category") Integer category);


    Page<NurseryScheduleRecord> findByCategoryAndNurseryScheduleIdIn( Integer category,String[] nurseryScheduleId,Pageable pageable);

    Page<NurseryScheduleRecord> findByCategoryInAndNurseryScheduleIdIn( Integer[] category,String[] nurseryScheduleId,Pageable pageable);


    Page<NurseryScheduleRecord> findByNurseryScheduleIdIn(String[] nurseryScheduleId,Pageable pageable);

}
